from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
import simplejson as json
import createDB

#Getting all places saved on the server and parsing it to a JSON object
class getRecords(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        Places = db.GqlQuery("SELECT * from Place")
        result = [{'name': str(Place.name), 'urls': str(Place.urls), 'lat': Place.Lat, 'lon': Place.Lon} for Place in Places]
        
        
        self.response.out.write(json.dumps(result))
        
application = webapp.WSGIApplication([('/getRecords', getRecords)], debug=True)
  
def main():
    run_wsgi_app(application)
    
if __name__ == "__main__":
    main()